package com.renhui.android.handwriting.hermes;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;
import android.widget.Toast;

import com.renhui.java.sutherland.R;

import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import xiaofei.library.hermeseventbus.HermesEventBus;

public class EvenMulitEventBusActivity extends AppCompatActivity {

    private TextView textView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        HermesEventBus.getDefault().register(this);
        setContentView(R.layout.activity_even_mulit_event_bus);
        textView = findViewById(R.id.text);
        findViewById(R.id.send_message).setOnClickListener(v -> {
            startActivity(new Intent(EvenMulitEventBusActivity.this, EvenMulitProcessActivity.class));
        });
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onEventBusCome(String message) {
        Log.e("EventBus",  Thread.currentThread().getName());
        Toast.makeText(this, message, Toast.LENGTH_SHORT).show();
        textView.setText(message);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        HermesEventBus.getDefault().destroy();
    }
}